package com.tang.invokecenter.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@Component
public class CmdInvokePy {
	//python入口文件路径
	@Value("${python}")
	String mainPython;

	public String invoke(String path) throws IOException, InterruptedException{
		String exe = "python";
		String[] cmdArr = new String[]{exe, mainPython, path};
		Process process = Runtime.getRuntime().exec(cmdArr);
		BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
		String line = reader.readLine();
		System.out.println(line);
//		while (reader.ready()) {
//			line = reader.readLine();
//
//		}
		process.waitFor();
		return line;
	}
}
